<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ObjectManager example</title>
<script src="../ObjectManager.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
/*
 * EXAMPLE
 * Defines a set of objects with various values and references to
 * demonstrate how the structure is kept identical through serialization.
 */

var a = { aString: 'hello', aNumber: 12.3, aBool: true, anArray: [1, 2, [3, 4]], anObject: { anotherObject: { hello: 'world', iAm: 1337 } } },
    b = { referenceToArray: a.anArray, referenceToA: a, referenceToSubObject: a.anObject.anotherObject, anotherString: 'weeee' },
    c = { references: [a, b] },
    d = [a, b, c];

// Create an ObjectManager instance and register variables a, b, c and d.
var manager = new ObjectManager();
manager.register(a, 'a');
manager.register(b, 'b');
manager.register(c, 'c');
manager.register(d, 'd');

// Serialize and deserialize the registered objects.
var serialized = manager.serialize();
var deserialized = ObjectManager.deserialize(serialized);

// (Firebug required)
// Shows the instances before and after serialization as well as the serialized
// version of the data.
console.log({
    before: [a, b, c, d],
    intermediate: serialized,
    after: [deserialized.objects['a'], deserialized.objects['b'], deserialized.objects['c'], deserialized.objects['d']]
});
</script>
</body>
</html>